﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// TSqlDBProc 的摘要说明
/// </summary>
public class TSqlDBProc
{
    private string FConnString;
    private string FProcName;

    private System.Data.SqlClient.SqlConnection FConnection;
    private System.Data.SqlClient.SqlCommand FCommand;
    public System.Data.SqlClient.SqlDataReader FDataReader;

    private System.Data.SqlClient.SqlConnection FConnection2;
    private System.Data.SqlClient.SqlCommand FCommand2;
    public System.Data.SqlClient.SqlDataReader FDataReader2;

    public TSqlDBProc(string ProcName, int iDR)
    {
        FConnString = GetConnString();

        if (iDR == 0)
        {
            FConnection = new SqlConnection(FConnString);
            FConnection.Open();
        }
        else
        {
            FConnection2 = new SqlConnection(FConnString);
            FConnection2.Open();
        }

        FProcName = ProcName;

    }

    protected static string GetConnString()
    {
        return System.Configuration.ConfigurationSettings.AppSettings["ConnStr"];
    }

    /// <summary>
    /// 调用ms_getnewid存储过程，返回sqlserver生成的ID。
    /// </summary>
    public string ms_GetNewID()
    {
        string Result;

        SqlCommand FCommand = new SqlCommand(FProcName, FConnection);
        FCommand.CommandType = CommandType.StoredProcedure;
        //输出参数
        SqlParameter myOutputParm = new SqlParameter("@newid", SqlDbType.UniqueIdentifier, 16);
        myOutputParm.Direction = ParameterDirection.Output;
        FCommand.Parameters.Add(myOutputParm);
        //执行
        FCommand.ExecuteNonQuery();
        //-----
        Result = myOutputParm.Value.ToString();
        return Result;
    }

    /// <summary>
    /// 调用ms_ChgStatus存储过程，更改用户状态。
    /// </summary>
    public void ms_ChgStatus(string employee_id)
    {
        SqlCommand FCommand = new SqlCommand(FProcName, FConnection);
        FCommand.CommandType = CommandType.StoredProcedure;
        //输入参数1:员工编号
        SqlParameter myInputParm1 = new SqlParameter("@employee_id", SqlDbType.VarChar, 20);
        myInputParm1.Value = employee_id;
        myInputParm1.Direction = ParameterDirection.Input;
        FCommand.Parameters.Add(myInputParm1);
        //执行
        FCommand.ExecuteNonQuery();
    }

    /// <summary>
    /// 调用ms_areacode存储过程，给区域自动编号。
    /// </summary>
    public string ms_areacode(string citycode)
    {
        string Result;

        SqlCommand FCommand = new SqlCommand(FProcName, FConnection);
        FCommand.CommandType = CommandType.StoredProcedure;
        //输入参数:citycode
        SqlParameter myInputParm = new SqlParameter("@citycode", SqlDbType.NVarChar, 2);
        myInputParm.Value = citycode;
        myInputParm.Direction = ParameterDirection.Input;
        FCommand.Parameters.Add(myInputParm);
        //输出参数:areacode
        SqlParameter myOutputParm = new SqlParameter("@areacode", SqlDbType.NVarChar, 5);
        myOutputParm.Direction = ParameterDirection.Output;
        FCommand.Parameters.Add(myOutputParm);
        //执行
        FCommand.ExecuteNonQuery();
        //-----
        Result = myOutputParm.Value.ToString();
        return Result;
    }

    /// <summary>
    /// 调用ms_mediacode存储过程，给媒体自动编号。
    /// </summary>
    public string ms_mediacode(string citycode)
    {
        string Result;

        SqlCommand FCommand = new SqlCommand(FProcName, FConnection);
        FCommand.CommandType = CommandType.StoredProcedure;
        //输入参数:citycode
        SqlParameter myInputParm = new SqlParameter("@citycode", SqlDbType.NVarChar, 2);
        myInputParm.Value = citycode;
        myInputParm.Direction = ParameterDirection.Input;
        FCommand.Parameters.Add(myInputParm);
        //输出参数:mediacode
        SqlParameter myOutputParm = new SqlParameter("@mediacode", SqlDbType.NVarChar, 6);
        myOutputParm.Direction = ParameterDirection.Output;
        FCommand.Parameters.Add(myOutputParm);
        //执行
        FCommand.ExecuteNonQuery();
        //-----
        Result = myOutputParm.Value.ToString();
        return Result;
    }

    /// <summary>
    /// 调用ms_contractcode存储过程，给合同自动编号。
    /// </summary>
    public string ms_contractcode(string citycode)
    {
        string Result;

        SqlCommand FCommand = new SqlCommand(FProcName, FConnection);
        FCommand.CommandType = CommandType.StoredProcedure;
        //输入参数:citycode
        SqlParameter myInputParm = new SqlParameter("@citycode", SqlDbType.NVarChar, 2);
        myInputParm.Value = citycode;
        myInputParm.Direction = ParameterDirection.Input;
        FCommand.Parameters.Add(myInputParm);
        //输出参数:contractcode
        SqlParameter myOutputParm = new SqlParameter("@contractcode", SqlDbType.NVarChar, 9);
        myOutputParm.Direction = ParameterDirection.Output;
        FCommand.Parameters.Add(myOutputParm);
        //执行
        FCommand.ExecuteNonQuery();
        //-----
        Result = myOutputParm.Value.ToString();
        return Result;
    }

    /// <summary>
    /// 调用ms_contractpaycode存储过程，给合同付款自动编号。
    /// </summary>
    public string ms_contractpaycode(string contractno)
    {
        string Result;

        SqlCommand FCommand = new SqlCommand(FProcName, FConnection);
        FCommand.CommandType = CommandType.StoredProcedure;
        //输入参数:contractno
        SqlParameter myInputParm = new SqlParameter("@contractno", SqlDbType.NVarChar, 9);
        myInputParm.Value = contractno;
        myInputParm.Direction = ParameterDirection.Input;
        FCommand.Parameters.Add(myInputParm);
        //输出参数:paycode
        SqlParameter myOutputParm = new SqlParameter("@paycode", SqlDbType.NVarChar, 11);
        myOutputParm.Direction = ParameterDirection.Output;
        FCommand.Parameters.Add(myOutputParm);
        //执行
        FCommand.ExecuteNonQuery();
        //-----
        Result = myOutputParm.Value.ToString();
        return Result;
    }

    /// <summary>
    /// 调用ms_mirrorcode存储过程，给镜面自动编号。
    /// </summary>
    public string ms_mirrorcode(string mediacode)
    {
        string Result;

        SqlCommand FCommand = new SqlCommand(FProcName, FConnection);
        FCommand.CommandType = CommandType.StoredProcedure;
        //输入参数:mediacode
        SqlParameter myInputParm = new SqlParameter("@mediacode", SqlDbType.NVarChar, 6);
        myInputParm.Value = mediacode;
        myInputParm.Direction = ParameterDirection.Input;
        FCommand.Parameters.Add(myInputParm);
        //输出参数:mirrorcode
        SqlParameter myOutputParm = new SqlParameter("@mirrorcode", SqlDbType.NVarChar, 8);
        myOutputParm.Direction = ParameterDirection.Output;
        FCommand.Parameters.Add(myOutputParm);
        //执行
        FCommand.ExecuteNonQuery();
        //-----
        Result = myOutputParm.Value.ToString();
        return Result;
    }

    /// <summary>
    /// 调用ms_GetLinkmanPage存储过程，分页显示用户的联系人。
    /// </summary>
    public void ms_GetLinkmanPage(int brn, int ern, string inman)
    {
        SqlCommand FCommand = new SqlCommand(FProcName, FConnection);
        FCommand.CommandType = CommandType.StoredProcedure;
        //输入参数1:开始行
        SqlParameter myInputParm1 = new SqlParameter("@StartRow", SqlDbType.Int);
        myInputParm1.Value = brn;
        myInputParm1.Direction = ParameterDirection.Input;
        FCommand.Parameters.Add(myInputParm1);
        //输入参数2:结束行
        SqlParameter myInputParm2 = new SqlParameter("@StopRow", SqlDbType.Int);
        myInputParm2.Value = ern;
        myInputParm2.Direction = ParameterDirection.Input;
        FCommand.Parameters.Add(myInputParm2);
        //输入参数3:用户ID
        SqlParameter myInputParm3 = new SqlParameter("@inman", SqlDbType.NVarChar,100);
        myInputParm3.Value = inman;
        myInputParm3.Direction = ParameterDirection.Input;
        FCommand.Parameters.Add(myInputParm3);
        //执行
        FDataReader = FCommand.ExecuteReader();
    }

    /// <summary>
    /// 调用ms_GetCheckList存储过程，分页显示赠阅名录
    /// </summary>
    public void ms_GetCheckList(int brn, int ern, int status)
    {
        SqlCommand FCommand = new SqlCommand(FProcName, FConnection);
        FCommand.CommandType = CommandType.StoredProcedure;
        //输入参数1:开始行
        SqlParameter myInputParm1 = new SqlParameter("@StartRow", SqlDbType.Int);
        myInputParm1.Value = brn;
        myInputParm1.Direction = ParameterDirection.Input;
        FCommand.Parameters.Add(myInputParm1);
        //输入参数2:结束行
        SqlParameter myInputParm2 = new SqlParameter("@StopRow", SqlDbType.Int);
        myInputParm2.Value = ern;
        myInputParm2.Direction = ParameterDirection.Input;
        FCommand.Parameters.Add(myInputParm2);
        //输入参数3:状态
        SqlParameter myInputParm3 = new SqlParameter("@stat", SqlDbType.Int);
        myInputParm3.Value = status;
        myInputParm3.Direction = ParameterDirection.Input;
        FCommand.Parameters.Add(myInputParm3);
        //执行
        FDataReader = FCommand.ExecuteReader();
    }

    /// <summary>
    /// 调用ms_GetNewsPage存储过程，分页显示信息。
    /// </summary>
    public void ms_GetNewsPage(int brn, int ern)
    {
        SqlCommand FCommand = new SqlCommand(FProcName, FConnection);
        FCommand.CommandType = CommandType.StoredProcedure;
        //输入参数1:开始行
        SqlParameter myInputParm1 = new SqlParameter("@StartRow", SqlDbType.Int);
        myInputParm1.Value = brn;
        myInputParm1.Direction = ParameterDirection.Input;
        FCommand.Parameters.Add(myInputParm1);
        //输入参数2:结束行
        SqlParameter myInputParm2 = new SqlParameter("@StopRow", SqlDbType.Int);
        myInputParm2.Value = ern;
        myInputParm2.Direction = ParameterDirection.Input;
        FCommand.Parameters.Add(myInputParm2);
        //执行
        FDataReader = FCommand.ExecuteReader();
    }

    /// <summary>
    /// 调用ms_GetTopicsPage存储过程，分页显示信息。
    /// </summary>
    public void ms_GetTopicsPage(int brn, int ern)
    {
        SqlCommand FCommand = new SqlCommand(FProcName, FConnection);
        FCommand.CommandType = CommandType.StoredProcedure;
        //输入参数1:开始行
        SqlParameter myInputParm1 = new SqlParameter("@StartRow", SqlDbType.Int);
        myInputParm1.Value = brn;
        myInputParm1.Direction = ParameterDirection.Input;
        FCommand.Parameters.Add(myInputParm1);
        //输入参数2:结束行
        SqlParameter myInputParm2 = new SqlParameter("@StopRow", SqlDbType.Int);
        myInputParm2.Value = ern;
        myInputParm2.Direction = ParameterDirection.Input;
        FCommand.Parameters.Add(myInputParm2);
        //执行
        FDataReader = FCommand.ExecuteReader();
    }

    /// <summary>
    /// 调用ms_GetContractPageByCode存储过程，根据编码分页显示。
    /// </summary>
    public void ms_GetContractPageByCode(int brn, int ern, string contractcode, int sortby)
    {
        SqlCommand FCommand = new SqlCommand(FProcName, FConnection);
        FCommand.CommandType = CommandType.StoredProcedure;
        //输入参数1:开始行
        SqlParameter myInputParm1 = new SqlParameter("@StartRow", SqlDbType.Int);
        myInputParm1.Value = brn;
        myInputParm1.Direction = ParameterDirection.Input;
        FCommand.Parameters.Add(myInputParm1);
        //输入参数2:结束行
        SqlParameter myInputParm2 = new SqlParameter("@StopRow", SqlDbType.Int);
        myInputParm2.Value = ern;
        myInputParm2.Direction = ParameterDirection.Input;
        FCommand.Parameters.Add(myInputParm2);
        //输入参数3:代码
        SqlParameter myInputParm3 = new SqlParameter("@contractcode", SqlDbType.NVarChar, 20);
        myInputParm3.Value = contractcode;
        myInputParm3.Direction = ParameterDirection.Input;
        FCommand.Parameters.Add(myInputParm3);
        //输入参数4:排序标示
        SqlParameter myInputParm4 = new SqlParameter("@sortby", SqlDbType.Int);
        myInputParm4.Value = sortby;
        myInputParm4.Direction = ParameterDirection.Input;
        FCommand.Parameters.Add(myInputParm4);
        //执行
        FDataReader = FCommand.ExecuteReader();
    }

    /// <summary>
    /// 调用ms_GetContractPageByName存储过程，根据名称分页显示。
    /// </summary>
    public void ms_GetContractPageByName(int brn, int ern, string medianame, int sortby)
    {
        SqlCommand FCommand = new SqlCommand(FProcName, FConnection);
        FCommand.CommandType = CommandType.StoredProcedure;
        //输入参数1:开始行
        SqlParameter myInputParm1 = new SqlParameter("@StartRow", SqlDbType.Int);
        myInputParm1.Value = brn;
        myInputParm1.Direction = ParameterDirection.Input;
        FCommand.Parameters.Add(myInputParm1);
        //输入参数2:结束行
        SqlParameter myInputParm2 = new SqlParameter("@StopRow", SqlDbType.Int);
        myInputParm2.Value = ern;
        myInputParm2.Direction = ParameterDirection.Input;
        FCommand.Parameters.Add(myInputParm2);
        //输入参数3:名称
        SqlParameter myInputParm3 = new SqlParameter("@medianame", SqlDbType.NVarChar, 50);
        myInputParm3.Value = medianame;
        myInputParm3.Direction = ParameterDirection.Input;
        FCommand.Parameters.Add(myInputParm3);
        //输入参数4:排序标示
        SqlParameter myInputParm4 = new SqlParameter("@sortby", SqlDbType.Int);
        myInputParm4.Value = sortby;
        myInputParm4.Direction = ParameterDirection.Input;
        FCommand.Parameters.Add(myInputParm4);
        //执行
        FDataReader = FCommand.ExecuteReader();
    }
}
